package com.xbh.boot_study.interceptor;

import com.xbh.boot_study.annotion.EnableLog;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;
import org.springframework.stereotype.Component;

/**
 * @LogInterceptor: 日志记录
 * @author: ZBoHang
 * @time: 2021/9/30 14:37
 */
@Slf4j
@Aspect
@Component
public class LogInterceptor {

    @Pointcut("execution( * com.xbh..controller..*.*(..))")
    public void logPointCut() {

    }

    @Before("logPointCut()")
    public void before(JoinPoint jp) {

        MethodSignature signature = (MethodSignature) jp.getSignature();
        EnableLog enableLog = signature.getMethod().getAnnotation(EnableLog.class);
        if (enableLog != null) {
            log.info("@@@@@@@@@@@ -->>  切面前");
            log.info(enableLog.modelName() + " ***** " + enableLog.behavior() + " ***** " + enableLog.remake());
        }
    }

    @After("logPointCut()")
    public void after(JoinPoint jp) {

        log.info("@@@@@@@@@@@ -->>  切面后");
    }

}
